<template>
  <div class="flex group_y_box">
    <div class="group_y_left p-12">
      <el-button type="primary" plain size="small" @click="handleAdd">
        <i class="el-icon-plus mr-10"></i> 添加分组</el-button
      >
      <div
        v-for="(item, index) in groupList"
        :key="index"
        class="g_item"
        :class="{ active: item.select }"
        @click="handleClick(item)"
      >
        <span>{{ item.name }}</span>
        <i
          class="el-icon-delete commhover"
          @click="handleDelete(item, index)"
        ></i>
      </div>
    </div>
    <div class="group_y_right p-12">
      <MaterialContent />
    </div>
  </div>
</template>
<script>
import MaterialContent from "../MaterialContent";
export default {
  data() {
    return {
      groupList: [],
      rowItem: null,
    };
  },
  components: {
    MaterialContent,
  },
  methods: {
    handleAdd() {
      if (this.groupList.length >= 10) {
        this.$message.warning("最多能创建10组内容");
        return;
      }
      this.groupList.push({
        name: "话术组" + (this.groupList.length + 1),
        select: false,
      });
    },

    handleDelete(item, index) {
      this.groupList.splice(index, 1);
    },

    handleClick(item) {
      this.groupList.forEach((item) => {
        item.select = false;
      });
      item.select = true;
      this.rowItem = item;
    },
  },
};
</script>
<style lang="scss" scoped>
.group_y_box {
  border: 1px solid #e9e9e9;
}
.group_y_left {
  width: 144px;
}
.group_y_right {
  flex: 1 1;
  border-left: 1px solid #e9e9e9;
}
.g_item {
  position: relative;
  padding: 5px 12px;
  margin-top: 8px;
  border-radius: 2px;
  transition: all 0.3s;
  cursor: pointer;
  line-height: normal;

  &:hover {
    background-color: #f7f7f7;
  }
  &.active{background-color: #f7f7f7;}

  i {
    position: absolute;
    top: 9px;
    right: 5px;
  }
}
</style>